#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
const int N = 1e6 + 5;

void solve() {
    int n, d;
    cin >> n >> d;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    sort(p.begin(),p.end());
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        auto it = upper_bound(p.begin(), p.end(), p[i] + d);
        cnt += (it - p.begin()) - i - 1;
    }
    cout << cnt << endl;
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();

    return 0;
}